<?php
/**
 * 场地管理
 * User: Administrator
 * Date: 2022/3/9
 * Time: 16:05
 */

namespace app\api\controller;
use app\common\controller\Api;
use think\Db;
use think\Request;

class Field extends Api
{
    protected $noNeedLogin = '*';
    protected $noNeedRight = '*';
    protected $model = null;
    public function _initialize()
    {
        parent::_initialize();
        $this->model = new \app\admin\model\sign_up\Programme;

    }

    /**
     * 选场地
     * */
    public function list()
    {
        if (!Request::instance()->isPost())
            $this->error('请求方式不正确');
        $page = input('post.page',1);
        $limit = input('post.limit',10);
        $where = [];
        $where['status'] = 1;
        if($title = input('post.title'))
        {
            $where['title'] = ['like','%'.$title.'%'];
        }

        if($base_type = input('post.base_type'))
        {
            $where['base_type'] = $base_type;
        }

        if($city = input('post.city'))
        {
            $where['city'] = $city;
        }
        $query = Db::name('field')->where($where)->field('id,title,image,city');
        if($supporting_services = input('post.supporting_services'))
        {
            $whereRow= "FIND_IN_SET('".$supporting_services."',supporting_services)";
            $query->whereRaw($whereRow);
        }
        $list = $query->paginate($limit,false,['page'=>$page]);
        if($list)
            $this->success('',$list);
        $this->error('暂无数据');

    }

    public function detail()
    {
        if (!Request::instance()->isGet())
            $this->error('请求方式不正确');
        if(!$id = input('get.id'))
            $this->error('缺少参数');

        $info = Db::name('field')->field('id,title,city,base_type,brief_introduction,details')->where('id',$id)->find();
        if(!$info)
            $this->error('无记录');
        $this->success('',$info);
    }

    public function serverList()
    {
        $data = [];
        $type = [
          '铁血基地',
          '合作基地',
        ];
        $addr = [
          '绍兴',
          '杭州',
          '上海',
          '苏州',
          '宁波',
          '上虞',
          '新昌',
          '诸暨',
          '嘉兴',
          '舟山',
        ];
        /*$server = [
            '真人cs'=>'真人cs',
            '基地客房'=>'基地客房',
            '农家土灶'=>'农家土灶',
            '民宿'=>'民宿',
            '背摔台'=>'背摔台',
            '攀岩墙'=>'攀岩墙',
            '风雨操场'=>'风雨操场',
            '户外烧烤'=>'户外烧烤',
            '会议室'=>'会议室',
            '学员宿舍'=>'学员宿舍',
            '教  室'=>'教  室',
            '训练场'=>'训练场',
            '大草坪'=>'大草坪',
            '毕业墙'=>'毕业墙',
            '军训器材'=>'军训器材',
            '食堂'=>'食堂',
            '农庄餐厅'=>'农庄餐厅',
            '高空架'=>'高空架',
            '大报告厅'=>'大报告厅',
            '户外篝火'=>'户外篝火',
        ];*/
        $server = [
            '真人cs',
            '基地客房',
            '农家土灶',
            '民宿',
            '背摔台',
            '攀岩墙',
            '风雨操场',
            '户外烧烤',
            '会议室',
            '学员宿舍',
            '教  室',
            '训练场',
            '大草坪',
            '毕业墙',
            '军训器材',
            '食堂',
            '农庄餐厅',
            '高空架',
            '大报告厅',
            '户外篝火',
        ];
        $data['type'] = $type;
        $data['addr'] = $addr;
        $data['server'] = $server;

        $this->success('',$data);
    }
}